package com.ketti.team;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import android.util.Log;

/**
 * @Date		: 2010. 5. 23. 
 * @Author		: chitacan
 * @Description	: helper class for access file in SD card
 **/
public class FileIO {
	private final String tag = "FileIO";
	
	public FileIO(){}		
	
	/**
	 * @Method			: getFileList
	 * @Date			: 2010. 5. 23. 
	 * @Author			: chitacan
	 * @Description		: file's list under specified path
	 * @param path		: path where user want to get list
	 * @return			: file's list
	 **/
	public String[] getFileList(String path){
		try{
			File file = new File(path);
			return file.list();
		} catch (SecurityException e) {
			Log.i(tag, e.getMessage());
		}
		return null;
	}
	
	/**
	 * @Method			: readFile
	 * @Date			: 2010. 5. 23. 
	 * @Author			: chitacan
	 * @Description		: read file under specified path 
	 * @param path		: file's path what user want to open
	 * @param fileName	: file's name what user want to open
	 * @return			: file's content
	 **/
	public String readFile(String path, String fileName){
		String source = null;
				
		try {
			File file = new File(path + fileName);			
			FileReader fileReader = new FileReader(file);
			BufferedReader bufferedReader = new BufferedReader(fileReader);
			String line = null;
			while((line = bufferedReader.readLine()) != null){
				if(source == null)
					source = (line + "\n");
				else
					source += (line + "\n");				
			}
			bufferedReader.close();
		} catch (IOException e) {
			Log.i(tag, e.getMessage());
		}
		
		return source;
	}
}
